<template>
  <div>
    <BasicTable @register="registerTable">
      <template #toolbar>
        <a-button type="primary" @click="handleCreate"> 新增介绍人 </a-button>
        <div style="display: flex;margin-left: 10px;">
          <div>
            <span style="font-size: 15px">介绍人</span>
            <Tooltip placement="top" :overlayStyle="{ width: '200px' }">
              <template #title>
                <div>
                  <div>按照客户编号，在接单人，跟单人的基础上 抽成金额划拨一部分费用给介绍人</div>
                </div>

              </template>
              <InfoCircleOutlined style="margin-left: 5px; color: #cc8500; font-size: 19px; cursor: pointer" />
            </Tooltip>
          </div>

        </div>

      </template>
      <template #bodyCell="{ column, record }">
        <template v-if="column.key === 'action'">
          <TableAction :actions="[

            {
              icon: 'clarity:note-edit-line',
              onClick: handleEdit.bind(null, record),
            },
            {
              icon: 'ant-design:delete-outlined',
              color: 'error',
              popConfirm: {
                title: '是否确认删除',
                placement: 'left',
                confirm: handleDelete.bind(null, record),
              },
            },
          ]" />
        </template>
      </template>
    </BasicTable>
    <FormModal @register="register" @success="handleSuccess" />
  </div>
</template>
<script lang="ts" setup>
import { BasicTable, useTable, TableAction } from '@/components/Table';
import { introduceUserList, introduceUserDelete } from '@/api/heng/ywManage';
import { onMounted } from 'vue';

import FormModal from './FormModal.vue';

import { columns, searchFormSchema } from './role.data';
import { useMessage } from "@/hooks/web/useMessage";
import { useModal } from "@/components/Modal";
import { useGo } from "@/hooks/web/usePage";
import {Tooltip} from "ant-design-vue";
import {InfoCircleOutlined} from "@ant-design/icons-vue";

const go = useGo();

defineOptions({ name: 'ywDeptList' });
const { createMessage } = useMessage();

const [register, { openModal, closeModal }] = useModal();

const [registerTable, { reload }] = useTable({
  title: '介绍人列表',
  api: introduceUserList,
  columns,
  formConfig: {
    labelWidth: 120,
    schemas: searchFormSchema,
    autoSubmitOnEnter: true
  },
  useSearchForm: true,
  showTableSetting: true,
  bordered: true,
  showIndexColumn: false,
  actionColumn: {
    width: 80,
    title: '操作',
    dataIndex: 'action',
    // slots: { customRender: 'action' },
    fixed: undefined,
  },
});

function handleCreate() {
  openModal(true, {
    isUpdate: false,
  });
}

onMounted(() => {
  // dd.ready(function() {
  //
  // }
})


function handleEdit(record: Recordable) {
  openModal(true, {
    record,
    isUpdate: true,
  });
}



function handleDelete(record: Recordable) {
  //console.log(record);

  introduceUserDelete(record).then(res => {
    createMessage.success(res.message);
  })
    .catch((res) => {
      createMessage.error(res.message);
    })
    .finally(() => {
      reload();
    });
}

function handleSuccess() {
  reload();
}
</script>
